package me.sunpeng.principle.singleresponsibility;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author sp
 * @create 2022-08-29
 */
public class Test {
    public static void main(String[] args) {
        String text = "abcd text read read word";
        String[] words = text.split(" ");
        HashMap<String, Integer> wordCount = new HashMap<>();
        for (int i = 0; i < words.length; i++) {
            String key = words[i];
            if (wordCount.containsKey(key)) {
                wordCount.put(key, wordCount.get(key) + 1);
            } else {
                wordCount.put(key, 1);
            }
        }
        TreeMap treeMap = new TreeMap(wordCount);

        for (int i = 0; i < 3; i++) {
            System.out.println(treeMap.lastKey());
            treeMap.remove(treeMap.lastKey());
        }

        Map<Integer, List<String>> collect = Arrays.stream(words).collect(Collectors.groupingBy(String::length));



    }
}
